/*
 * Copyright (C) 2009 Leandro de Oliveira Aparecido <lehphyro@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.japa.repository;

import java.util.*;

import org.springframework.core.*;

/**
 * Base class to method parameter name discoverers.
 * 
 * @author Leandro Aparecido
 * @since 1.0
 * @see org.springframework.core.ParameterNameDiscoverer
 * @see com.google.code.japa.repository.query.RepositoryQueryAnnotationParameterNameDiscoverer
 * @see com.google.code.japa.repository.ret.RepositoryReturnAnnotationParameterNameDiscoverer
 */
public abstract class RepositoryAnnotationParameterNameDiscoverer implements ParameterNameDiscoverer {

	/**
	 * Returns the parameters names parsing the given input string.
	 * 
	 * @param namesToParse Names to parse.
	 * <p>Should be in the following format: a,b,c where a, b and c are the parameter names.
	 * @return Parsed parameter names.
	 */
	protected String[] getParameterNames(String namesToParse) {
		String[] names = null;

		StringTokenizer tokenizer = new StringTokenizer(namesToParse, ",");
		if (tokenizer.countTokens() > 0) {
			names = new String[tokenizer.countTokens()];
			for (int i = 0; i < names.length; i++) {
				names[i] = tokenizer.nextToken();
			}
		}

		return names;
	}
}
